package com.winshare.saleAssistant.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.winshare.saleAssistant.dao.SchoolHardwareMapper;
import com.winshare.saleAssistant.domain.dto.req.PageQueryDTO;
import com.winshare.saleAssistant.domain.dto.req.UserQueryDTO;
import com.winshare.saleAssistant.model.SchoolHardware;
import com.winshare.saleAssistant.model.TUser;
import com.winshare.saleAssistant.service.ISchoolHardwareService;
import com.winshare.saleAssistant.util.ToolUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 学校硬件数据 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2020-12-28
 */
@Service
public class SchoolHardwareServiceImpl extends ServiceImpl<SchoolHardwareMapper, SchoolHardware> implements ISchoolHardwareService {

    @Override
    public List<SchoolHardware> getUndistributed(String schoolCode, Page<SchoolHardware> page) {
        return this.baseMapper.getUndistributed(schoolCode, page);
    }

    @Override
    public com.winshare.saleAssistant.util.Page<SchoolHardware> getSchoolByPage(UserQueryDTO userQueryDTO) {
        QueryWrapper<SchoolHardware> queryWrapper = new QueryWrapper<>();
        if (ToolUtil.isNotEmpty(userQueryDTO.getSchoolName())) {
            queryWrapper.like("school_name",userQueryDTO.getSchoolName());
        }
        if (ToolUtil.isNotEmpty(userQueryDTO.getCityName())) {
            queryWrapper.eq("city_name",userQueryDTO.getCityName());
        }
        int totalCount = this.baseMapper.selectCount(queryWrapper);
        Integer pageIndex = userQueryDTO.getPageIndex();
        Integer pageSize = userQueryDTO.getPageSize();
        if (0 == totalCount) {
            return new com.winshare.saleAssistant.util.Page<>(pageIndex, pageSize, totalCount, new ArrayList<>());
        } else {
            return new com.winshare.saleAssistant.util.Page<>(pageIndex, pageSize, totalCount, this.baseMapper.getSchoolByPage(userQueryDTO));
        }
    }
}
